Resolve merge conflicts and clean up benchmark files#562
Draft
Copilot wants to merge 11 commits intobolt-optimize-closure-count-queries-6106104410388610831from
Draft
Resolve merge conflicts and clean up benchmark files#562Copilot wants to merge 11 commits intobolt-optimize-closure-count-queries-6106104410388610831from
Copilot wants to merge 11 commits intobolt-optimize-closure-count-queries-6106104410388610831from
Conversation
💡 What: - Optimized `ThreadSafeCache` by using `collections.OrderedDict` for timestamps. - Improved `_cleanup_expired` complexity from O(N) to O(K) where K is the number of expired entries. - Replaced manual dictionary-based caching in `backend/routers/detection.py` with `ThreadSafeCache`. 🎯 Why: - O(N) cache cleanup on every `set` operation causes unnecessary latency as the cache grows. - Manual caching in the detection router lacked thread safety and efficient eviction. 📊 Impact: - `ThreadSafeCache.set` performance improved by ~32x in benchmarks (from ~10.5k ops/sec to ~342k ops/sec). - Detection router now has robust, thread-safe caching with proper TTL and LRU eviction. 🔬 Measurement: - Run `backend/tests/benchmark_cache.py` to verify ops/sec improvement. - Run `backend/tests/test_cache_unit.py` to verify correctness.
What: Consolidated multiple separate `db.query(func.count(ClosureConfirmation.id)).filter(...)` database calls into a single `GROUP BY` query in `get_closure_status` and `check_and_finalize_closure`. Why: In high-traffic environments, executing multiple sequential aggregate queries on the same table causes unnecessary database roundtrips and scan overhead. Impact: Reduces database roundtrips from two separate counts to a single group by query when fetching or finalizing a grievance closure status. Measurement: Local benchmarking shows a latency reduction from ~0.214ms to ~0.159ms per call (a ~25% speedup) using SQLite. Performance gains will be even more significant with network-bound PostgreSQL in production.
…ctionality in ReportForm Replaced standard file input with a reliable react-webcam modal, allowing users to capture issue photos directly in the web app. The base64 output is automatically converted to a File object, maintaining compatibility with the existing API. Confirmed that Netlify/Render deployment configuration files (`netlify.toml` and `render.yaml`) and Hugging Face configuration are already properly set up in the repository.
…ment Removed `frontend/public/_redirects` which conflicts with the redirect rules already defined in the root `netlify.toml` file. This resolves the Netlify CI check failures for 'Redirect rules' and 'Header rules'.
…ed features - Removed `frontend/public/_redirects` which conflicts with the redirect rules already defined in the root `netlify.toml` file, resolving the Netlify deployment CI check failures for 'Redirect rules' and 'Header rules'. - Replaced standard file input with a reliable react-webcam modal, allowing users to capture issue photos directly in the web app, maintaining compatibility with the existing API. - Integrated a new Hugging Face facial emotions detection model (`dima806/facial_emotions_image_detection`), exposing it via `/api/detect-emotion` in the backend and updating the frontend API client.
…uild Fixed a syntax error in `frontend/src/api/detectors.js` which caused `vite build` to fail silently, leading to Netlify's deployment failure (`Pages changed` and `Redirect rules` checks). The error was introduced during the Hugging Face emotion detector integration patch. The local build now completes successfully.
…9847583124469405 ⚡ Bolt: Optimize ThreadSafeCache and detection router caching
…us-4445710699147296264 ⚡ Bolt: Optimize grievance closure status performance
…e0870e71 Integrate react-webcam for reliable in-app camera functionality in ReportForm
Copilot
AI
changed the title
[WIP] [6106104410388610831] Optimize closure status queries using GROUP BY
Resolve merge conflicts and clean up benchmark files
Mar 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Both this branch and
mainindependently applied the sameGROUP BYoptimization to closure status queries, causing conflicts. Mergedmainand resolved conflicts, plus addressed reviewer feedback on the benchmark files.Description
Conflict resolution (
backend/closure_service.py,backend/routers/grievances.py):main's more compact versionbackend/tests/test_closure_status_benchmark.py:sys,osimportsengine/create_allinto_make_session()to prevent DB side effects at pytest collection timetest_grouped_query_faster_than_separate()pytest function verifying correct counts from the GROUP BY querybackend/tests/benchmark_closure_status.py:sys,os,get_db,ClosureService,patch,MagicMock, andsys.path.insertseed_data()to populate all required non-nullGrievancefields (severity,current_jurisdiction_id,assigned_authority,sla_deadline) — previously would raiseIntegrityErroron commitType of Change
Related Issue
Closes #
Testing Done
Screenshots (if applicable)
Checklist
Co-Authors
📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.
Summary by cubic
Optimizes closure status counts with a single GROUP BY query and replaces detection caching with a faster, thread‑safe cache. Adds facial emotion detection and an in‑app camera capture to improve reporting. Aligns with Linear 6106104410388610831.
Refactors
closure_serviceandgrievancesrouter; preserves API shape (missing statuses → 0).ThreadSafeCache(TTL+LRU, O(K) expiry cleanup) to reduce latency.New Features
/api/detect-emotionendpoint using Hugging Facedima806/facial_emotions_image_detectionanddetectorsApi.emotionclient method.react-webcamto snap photos; converts captures to File for existing upload flow.frontend/public/_redirectsto fix Netlify deploy.Written for commit 23a5e8e. Summary will update on new commits.